import { IResult } from '@/store/reducer/search';
import { Image } from 'antd-mobile';
import classnames from 'classnames';
import styles from './index.module.scss';

import imgSrc from '@/assets/none.png';
import { IArticle } from '@/store/reducer/article';
import { useHistory } from 'react-router-dom';
interface IArticleItemProps {
  data: IResult | IArticle;
}

export default function ArticleItem({ data }: IArticleItemProps) {
  const { cover } = data;
  const { type, images } = cover || {};
  const history = useHistory();
  return (
    <div className={styles.root} onClick={() => history.push('/article/' + data.art_id)}>
      <div
        className={classnames('article-content', {
          t3: type === 3,
          'none-mt': type === 0,
        })}
      >
        <h3>{data.title}</h3>
        {type !== 0 && (
          <div className="article-imgs">
            {images?.map((item, index) => {
              return (
                <div key={index} className="article-img-wrapper">
                  <Image
                    lazy
                    fit="cover"
                    src={item}
                    fallback={<img src={imgSrc} alt="" />}
                    alt=""
                  />
                </div>
              );
            })}
          </div>
        )}
      </div>
      <div className={classnames('article-info', type === 0 ? 'none-mt' : '')}>
        <span>{data.aut_name}</span>
        <span>{data.comm_count}评论</span>
        <span>{data.pubdate}</span>
      </div>
    </div>
  );
}
